package com.anlogic.sdk.utils.toolchain;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.apache.logging.log4j.Logger;

import com.anlogic.sdk.utils.EnvUtils;
import com.anlogic.sdk.utils.LogUtils;

public class ToolchainProperty {
	private static Logger logger = LogUtils.getLogger(ToolchainProperty.class);
	
	private static final String PROPERTIES = "com.anlogic.sdk.utils.toolchain.toolchain";

	private static ResourceBundle RESOURCE_BUNDLE;

	static {
		try {
			RESOURCE_BUNDLE = ResourceBundle.getBundle(PROPERTIES);
		} catch (MissingResourceException e) {
			logger.error("Error to load toolchain property file");
		}
	}

	public static String getString(String key) {
		String ret = "";
		try {
			if (EnvUtils.isLinux()) {
				ret = fixToolchain(key);
			} else {
				ret = RESOURCE_BUNDLE.getString(key);
			}
		} catch (MissingResourceException e) {
		}
		return ret;
	}

	public static String fixToolchain(String key) {
		String ret = "";
		if (key.equals("BUILD_TOOL_PATH")) {
			ret = RESOURCE_BUNDLE.getString("LINUX_BUILD_TOOL_PATH");
		} else {
			ret = RESOURCE_BUNDLE.getString(key);
		}

		return ret;
	}
}
